#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maximumCostSubstring(string s, string chars, vector<int>& vals) {
        unordered_map<char, int> hashch;
        for (int i = 0; i < chars.size(); i++) hashch[chars[i]] = vals[i];
        int n = s.size(), ret = 0;
        vector<int> dp(n);
        for (int i = 0; i < n; i++)
        {
            int val = 0;
            if (hashch.find(s[i]) != hashch.end()) val = hashch[s[i]];
            else val = s[i] - 'a' + 1;
            if (i == 0) dp[i] = val;
            else dp[i] = max(dp[i - 1] + val, val);
            ret = max(ret, dp[i]);
        }
        return ret;
    }
};